[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
putenv() Create New Environment Variables
#include <stdlib.h> Required for declarations only
int putenv(envstring);
const char *envstring; Environment string definition
putenv() adds new environment variables or modifies existing ones.
'envstring' must be a pointer to a string with the form:
varname=string
where 'varname' is the name of the environment variable to be added
or modified and 'string' is the value of the variable (for example:
INCLUDE = C:\INCLUDE). If the specified 'varname' is already set,
its value is replaced by 'string'. If it is not already set,
'envstring' is added to the environment. If the specified 'varname'
is already set, and 'string' is empty, 'varname' is deleted.
Returns: 0, if successful; -1 if an error occurs
Notes: Do not free a pointer to an environment variable
while the entry is still in use, or the environment
variable will point into freed space. This can
effectively happen if you pass a pointer to a local
variable to putenv(), and then exit the function in
which the local variable was declared.
-------------------------------- Example ---------------------------------
The following statements change the PATH to C:\WORK, and then print
an appropriate message.
#include <stdlib.h>
int result;
main()
{
if ((result = putenv("PATH=C:\\WORK")) == 0)
printf("path changed to C:\\WORK");
}
See Also:
getenv()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson